/**
 * 本地缓存工具类
 */
const $storage = {
    setItem: (key, value) => {
        localStorage.setItem(key, value)
    },
    getItem: (key) => {
        return localStorage.getItem(key)
    },
    removeItem: (key) => {
        localStorage.removeItem(key)
    }
}

const $token = {
    getToken: () => {
        const chatUserInfo = $storage.getItem('chatUserInfo');
        if (chatUserInfo) {
            const data = JSON.parse(chatUserInfo);
            return data.token;
        }
    },
    getAvatar: () => {
        const chatUserInfo = $storage.getItem('chatUserInfo');
        if (chatUserInfo) {
            const data = JSON.parse(chatUserInfo);
            return data.avatar;
        }
    },
    getUsername: () => {
        const chatUserInfo = $storage.getItem('chatUserInfo');
        if (chatUserInfo) {
            const data = JSON.parse(chatUserInfo);
            return data.username;
        }
    },
    getUserId: () => {
        const chatUserInfo = $storage.getItem('chatUserInfo');
        if (chatUserInfo) {
            const data = JSON.parse(chatUserInfo);
            return data.userId;
        }
    },
    clearAll: () => {
        $storage.removeItem('chatUserInfo');
    }
}

export {
    $storage,
    $token
}